import { Injectable, NestInterceptor, ExecutionContext, CallHandler, HttpCode, HttpStatus } from '@nestjs/common';
import { Observable } from 'rxjs';
import { map, tap } from 'rxjs/operators';

/**
 * 请求成功拦截
 */
@Injectable()
export class HttpSuccessInterceptor implements NestInterceptor {
  intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
    return next
      .handle()
      .pipe(
        map(data => {
          return {
            message: '成功',
            success: true,
            statusCode: HttpStatus.OK,
            ...data
          }
        })
      )
  }
}